package com.xueyi.aixihu.controller;

import com.xueyi.aixihu.controller.base.BaseController;
import com.xueyi.aixihu.entity.vo.FindRuleFatherVo;
import com.xueyi.aixihu.response.FindRuleByRoleResponse;
import com.xueyi.aixihu.response.base.BaseResponse;
import com.xueyi.aixihu.service.DtAuthRuleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import java.util.List;

/**
 * @author lvyi
 * @date : 2022/8/19
 * @Description : 权限表的controller层
 */
@RestController
public class DtAuthRuleController extends BaseController {

    @Autowired
    private DtAuthRuleService dtAuthRuleService;

    /**
     * 根据角色id查询其权限id
     *
     * @return
     */
    @RequestMapping("/authRule/findRuleByRole")
    public FindRuleByRoleResponse findRuleByRole(Integer id) {
        return dtAuthRuleService.findRuleByRole(id);
    }

    /**
     * 查询出树状图样的权限名称与id
     *
     * @return
     */
    @RequestMapping("/authRule/findTreeOutRule")
    public BaseResponse<List<FindRuleFatherVo>> findTreeOutRule() {
        return dtAuthRuleService.findTreeOutRule();
    }

    /**
     * 根据角色id关联权限
     *
     * @param id     角色id
     * @param ruleId 权限id
     */
    @RequestMapping("/authRule/updateRulesByRole")
    public BaseResponse<Boolean> updateRulesByRole(Integer id, String ruleId) {
        return dtAuthRuleService.updateRulesByRole(id, ruleId);
    }

}
